﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;
using Component.Worker.RecursiveProcess;

public partial class Controls_Tour_ctrTourSearch : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        SetMulLang();
        BindDataSafeOffToDropdownList();
        BindDataStartDestinationToDropdownList();
        BindDataToTypeTourDropDownList();
        BindDataToCountryDropdown();
        BindDataToRegionDropdown(0);
        BindDataToCatelogyDropdown(0, 0);
    }
    private void SetMulLang()
    {
        lblKeyWord.Text = MultipleLanguage.LBL_KEYWORD[nCurrentLang - 1];
        lblSaleOff.Text = MultipleLanguage.SALEOFF[nCurrentLang - 1];
        lblTourCat.Text = MultipleLanguage.TOURCATEGORY[nCurrentLang - 1];
        lblTourDest.Text = MultipleLanguage.TOURDESTINATION[nCurrentLang - 1];
        lblTourDuration.Text = MultipleLanguage.LBL_DURATION[nCurrentLang - 1];
    }
    private void BindDataToTypeTourDropDownList()
    {
        ddlTourDuration.DataSource = Support.dtbTourType(nCurrentLang);
        ddlTourDuration.DataTextField = "Description";
        ddlTourDuration.DataValueField = "Value";
        ddlTourDuration.DataBind();
    }
    private void BindDataSafeOffToDropdownList()
    {
        SaleOff obj = new SaleOff();
        DataTable dtb = new DataTable();

        dtb = obj.GetALL();
        ddlTourSaleOff.DataSource = dtb;

        switch (nCurrentLang)
        {
            case 1:
                ddlTourSaleOff.DataTextField = "Title1";
                break;
            case 2:
                ddlTourSaleOff.DataTextField = "Title2";
                break;
            case 3:
                ddlTourSaleOff.DataTextField = "Title3";
                break;
        }
        ddlTourSaleOff.DataValueField = "SaleOffID";
        ddlTourSaleOff.DataBind();
        Utl.SetNonSelectToControl(ddlTourSaleOff, MultipleLanguage.AllTextItem[nCurrentLang -1], "0");
    }
    private void BindDataStartDestinationToDropdownList()
    {
        TourDestination obj = new TourDestination();
        DataTable dtb = new DataTable();

        dtb = obj.GetALL();
        ddlTourDest.DataSource = dtb;

        switch (nCurrentLang)
        {
            case 1:
                ddlTourDest.DataTextField = "TourDestinationTitle1";
                break;
            case 2:
                ddlTourDest.DataTextField = "TourDestinationTitle2";
                break;
            case 3:
                ddlTourDest.DataTextField = "TourDestinationTitle3";
                break;
        }
        ddlTourDest.DataValueField = "TourDestinationID";
        ddlTourDest.DataBind();
        Utl.SetNonSelectToControl(ddlTourDest, MultipleLanguage.AllTextItem[nCurrentLang -1], "0");
    }
    protected void lnkSearch_Click(object sender, ImageClickEventArgs e)
    {
        string sKeyWord = ConvertData.ConvertToString(txtKeyword.Text);
        string sSaleOff = ConvertData.ConvertToString(ddlTourSaleOff.SelectedValue);
        string sTourDest = ConvertData.ConvertToString(ddlTourDest.SelectedValue);
        string sTourCat = ConvertData.ConvertToString(ddlTourCat.SelectedValue);
        string sCountry = ConvertData.ConvertToString(ddlCountry.SelectedValue);
        string sRegion = ConvertData.ConvertToString(ddlRegion.SelectedValue);
        string sTourDuration = ConvertData.ConvertToString(ddlTourDuration.SelectedValue);
        
        string sLink = Config.ROOT + Pages.FrontEnds.TOUR_LIST + "?"
            + Config.TOUR_SALEOFF + "=" + sSaleOff
            + "&" + Config.TOUR_DES + "=" + sTourDest

            + "&" + Config.TOUR_DURATION + "=" + sTourDuration
            + "&" + Config.TOUR_CAT + "=" + sTourCat
            + "&" + Config.TOUR_REGION + "=" + sRegion
            + "&" + Config.TOUR_COUNTRY + "=" + sCountry

            + "&" + Config.KEYWORD + "=" + sKeyWord;
        Response.Redirect(sLink);
    }
    
    private void BindDataToCountryDropdown()
    {
        DataTable dtbCountry = new DataTable();
        Country objCountry = new Country();
        dtbCountry = objCountry.GetALL();

        ddlCountry.DataSource = dtbCountry;
        ddlCountry.DataValueField = "CountryID";
        switch (ConvertData.ConvertToInt(Support.GetCurrentLanguage()))
        {
            case 1:
                ddlCountry.DataTextField = "CountryName1";
                break;
            case 2:
                ddlCountry.DataTextField = "CountryName2";
                break;
            case 3:
                ddlCountry.DataTextField = "CountryName3";
                break;
        }
        ddlCountry.DataBind();
        Utl.SetNonSelectToControl(ddlCountry, MultipleLanguage.AllTextItem[nCurrentLang -1], MultipleLanguage.AllTextItem[nCurrentLang -1]);
    }
    private void BindDataToRegionDropdown(int nCountry)
    {
        DataTable dtbRegion = new DataTable();
        Region objRegion = new Region();
        dtbRegion = objRegion.SearchByCountry(nCountry);
        ddlRegion.DataSource = dtbRegion;
        ddlRegion.DataValueField = "RegionID";
        switch (ConvertData.ConvertToInt(Support.GetCurrentLanguage()))
        {
            case 1:
                ddlRegion.DataTextField = "RegionName1";
                break;
            case 2:
                ddlRegion.DataTextField = "RegionName2";
                break;
            case 3:
                ddlRegion.DataTextField = "RegionName3";
                break;
        }
        ddlRegion.DataBind();
        Utl.SetNonSelectToControl(ddlRegion, MultipleLanguage.AllTextItem[nCurrentLang -1], MultipleLanguage.AllTextItem[nCurrentLang -1]);
    }
    private void BindDataToCatelogyDropdown(int nRegion, int nCountry)
    {
        DataTable dtbTourCat = new DataTable();
        TourCategory objTourCat = new TourCategory();
        dtbTourCat = objTourCat.Search(nRegion, nCountry);
        ddlTourCat.DataSource = dtbTourCat;
        ddlTourCat.DataValueField = "TourCategoryID";
        switch (ConvertData.ConvertToInt(Support.GetCurrentLanguage()))
        {
            case 1:
                ddlTourCat.DataTextField = "TourCategoryName1";
                break;
            case 2:
                ddlTourCat.DataTextField = "TourCategoryName2";
                break;
            case 3:
                ddlTourCat.DataTextField = "TourCategoryName3";
                break;
        }
        ddlTourCat.DataBind();
        Utl.SetNonSelectToControl(ddlTourCat, MultipleLanguage.AllTextItem[nCurrentLang -1], MultipleLanguage.AllTextItem[nCurrentLang -1]);
    }
    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        int nCountry = ConvertData.ConvertToInt(ddlCountry.SelectedValue);
        BindDataToRegionDropdown(nCountry);
        int nRegion = ConvertData.ConvertToInt(ddlRegion.SelectedValue);
        BindDataToCatelogyDropdown(nRegion, nCountry);
    }
    protected void ddlRegion_SelectedIndexChanged(object sender, EventArgs e)
    {
        int nCountry = ConvertData.ConvertToInt(ddlCountry.SelectedValue);
        int nRegion = ConvertData.ConvertToInt(ddlRegion.SelectedValue);
        BindDataToCatelogyDropdown(nRegion, nCountry);
    }
}